package com.aaa.stock.service.invent.impl;

import com.aaa.entity.InventoryLog;
import com.aaa.entity.Medicines;
import com.aaa.stock.dao.invent.InventoryDao;
import com.aaa.stock.dao.medic.MedicinesDao;
import com.aaa.stock.service.invent.InventoryService;
import com.aaa.stock.service.medic.StoMediService;
import com.aaa.stock.vo.InventoryVo;
import com.aaa.stock.vo.MedicinesVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Objects;

@Service
public class InventoryServiceImpl implements InventoryService {
    @Autowired
    private InventoryDao inventoryDao;

    @Override
    public Result<IPage<InventoryLog>> findInvAll(Integer currentPage, Integer pageSize, InventoryVo inventoryVo) {
        IPage<InventoryLog> page=new Page<>(currentPage,pageSize);
        QueryWrapper<InventoryLog> wrapper=new QueryWrapper<>();
        if(StringUtils.hasText(inventoryVo.getMedicinesName())){
            wrapper.like("medicines_name",inventoryVo.getMedicinesName());
        }
        if(StringUtils.hasText(inventoryVo.getPurchaseId())){
            wrapper.eq("purchase_id",inventoryVo.getPurchaseId());
        }
        if(StringUtils.hasText(inventoryVo.getMedicinesType())){
            wrapper.eq("medicines_type",inventoryVo.getMedicinesType());
        }
        if(StringUtils.hasText(inventoryVo.getProducerId())){
            wrapper.eq("producter_id",inventoryVo.getProducerId());
        }
        if(Objects.nonNull(inventoryVo.getPrescriptionType())){
            wrapper.eq("prescription_type",inventoryVo.getPrescriptionType());
        }
        if(Objects.nonNull(inventoryVo.getCreateTime())&&inventoryVo.getCreateTime().length==2){
            wrapper.between("create_time",inventoryVo.getCreateTime()[0],inventoryVo.getCreateTime()[1]);
        }

        IPage<InventoryLog> page1 = inventoryDao.selectPage(page, wrapper);
        return new Result<IPage<InventoryLog>>(2000,"查询库存成功",page1);
    }

}
